libxl: fd events: Suppress spurious fd events
authorIan Jackson <ian.jackson@eu.citrix.com>
Thu, 16 Apr 2015 18:23:28 +0000 (19:23 +0100)
committerIan Campbell <ian.campbell@citrix.com>
Wed, 22 Apr 2015 13:54:37 +0000 (14:54 +0100)
commit56d2350bf542ad5fd20d20e4e9dac76e8d9a54fe
treec3e11d1e1f29e838da793ddb402a7bff78cba874
parent0ade02ba3a74f4e5461d471c3e0fbcde4a00119e
libxl: fd events: Suppress spurious fd events

Always recheck with poll() right before making the callback.

All sorts of things may have happened since poll() originally signaled
the fd.  We would like the main functional libxl code not to have to
worry about spurious wakeups.

In particular, this fixes a bug in the save/restore callout: the save
helper message reader operates with the fd in blocking mode.  In a
multithreaded program one thread might have eaten all the messages out
of the fd while another one is busy returning from poll and reacquiring
the libxl lock, possibly resulting in a deadlock.

(Also, we abolish the anomalous direct caller of efd->func.)

Reported-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Reported-by: Jim Fehlig <jfehlig@suse.com>
Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
CC: Jim Fehlig <jfehlig@suse.com>
CC: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Tested-by: Jim Fehlig <jfehlig@suse.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
tools/libxl/libxl_event.c
tools/libxl/libxl_internal.h